﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/assets/libs/layui/css/layui.css" />
    <link rel="stylesheet" href="/assets/module/admin.css?v=318">
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>
<body>
    <!-- 主体部分 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 表格工具栏 -->
                <form class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">表名称:</label>
                            <div class="layui-input-inline">
                                <input name="TableName" class="layui-input" placeholder="输入" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            &emsp;
                            <button class="layui-btn icon-btn" lay-filter="userTbSearch" lay-submit>
                                <i class="layui-icon">&#xe615;</i>搜索
                            </button>
                        </div>
                    </div>
                </form>
                <!-- 数据表格 -->
                <table id="gridTable" lay-filter="gridTable"></table>
            </div>
        </div>
    </div>

    <!-- js部分 -->
    <script src="/assets/libs/jquery/jquery-3.2.1.min.js"></script>
    <script src="/assets/libs/layui/layui.js"></script>
    <script src="/assets/js/utils.js"></script>
    <script src="/assets/js/main.js"></script>
    <script>
        layui.use(['layer', 'form', 'table', 'util', 'admin', 'setter'], function () {
            var $ = layui.jquery;
            var layer = layui.layer;
            var form = layui.form;
            var table = layui.table;
            var util = layui.util;
            var admin = layui.admin;
            var setter = layui.setter;

            layuiTableSet();

            /* 渲染表格 */
            var insTb = table.render({
                elem: '#gridTable',
                url: setter.baseServer + '/SystemManage/Database/GetTablePageListJson',
                page: true,
                toolbar: ['<p>',
                    '<button lay-event="generate" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon">&#xe64e;</i>生成代码</button>&nbsp;',
                    '<button lay-event="templet" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon">&#xe656;</i>代码模板</button>&nbsp;',
                    '</p>'].join(''),
                cellMinWidth: 100,
                cols: [[
                    { type: 'checkbox' },
                    { field: 'Id', title: 'Id', visible: false },
                    { field: 'TableName', title: '表名称', sortable: true },
                    { field: 'TableKeyName', title: '主键名称' },
                    { field: 'TableKey', title: '主键字段' },
                    { field: 'TableCount', title: '记录数' },
                    { field: 'Remark', title: '备注' }
                ]]
            });

            /* 表格搜索 */
            form.on('submit(userTbSearch)', function (data) {
                insTb.reload({ where: data.field, page: { curr: 1 } });
                return false;
            });

            /* 表格头工具栏点击事件 */
            table.on('toolbar(gridTable)', function (obj) {
                if (obj.event === 'generate') { // 生成
                    var checkRows = table.checkStatus('gridTable');
                    if (checkRows.data.length === 0) {
                        layer.msg('请选择数据', { icon: 2 });
                        return;
                    }
                    if (checkRows.data.length > 1) {
                        layer.msg('只能选择一条数据', { icon: 2 });
                        return;
                    }
                    var d = checkRows.data.map(function (d) {
                        return d;
                    });
                    showGenerate(d[0]);
                } else if (obj.event === 'templet') {
                    admin.open({
                        type: 2,
                        area: ['80%', '90%'],
                        title: "代码模板",
                        content: 'codeTempletIndex.html',
                    });
                }
            });

            /* 显示表单弹窗 */
            function showGenerate(mData) {
                admin.open({
                    type: 2,
                    area: ['80%', '750px'],
                    title: "代码生成",
                    content: 'codeGeneratorForm.html?tableName=' + mData.TableName,
                });
            }

        });
    </script>
</body>
</html>